import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sports_new/entity/match/match_live_entity.dart';
import 'package:sports_new/utils/utils.dart';

import '../../../resources/colours.dart';
import '../../../widgets/base/qkd_text.dart';
import '../../../widgets/gif.dart';
import '../../../widgets/select_bottomsheet.dart';

class LiveSourceSheet extends StatelessWidget {
  const LiveSourceSheet({super.key, required this.liveList, this.isFullScreen = false, this.select});

  final List<MatchLiveEntity> liveList;
  final String? select;
  final bool isFullScreen;

  static Future<int?> show({
    required List<MatchLiveEntity> liveList,
    String? select,
    bool isFullScreen = false
  }) async{
    if(isFullScreen){
      return await Get.dialog(
        LiveSourceSheet(liveList: liveList,isFullScreen: isFullScreen,select: select,),
        barrierColor: Colours.transparent,
      );
    }else{
      return await Get.bottomSheet(
        LiveSourceSheet(liveList: liveList,select: select)
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return isFullScreen?fullScreenWidget():SelectBottomSheet(
      liveList.map((e) => e.name ?? '').toList(),
      select: select != null?liveList.indexWhere((element) => element.expertId == select || element.name == select):null,
      items: liveList.map(
        (e) => e.expertId != null?
        const GifWidget(
          width: 16,
          height: 16,
          asset: 'in_live_48.gif',
          duration: Duration(milliseconds: 500)
        ):Container()
      ).toList(),
      top: '请选择直播来源'
    );
  }

  Widget fullScreenWidget(){
    return Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        Container(
          width: 240,
          height: Get.height,
          color: Colours.black.withOpacity(0.8),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: List.generate(
              liveList.length,
              (index) => item(index)
            ).insertEvery(Container(height: 32))
          ),
        ),
      ],
    );
  }

  Widget item(int index){
    return GestureDetector(
      onTap: () => Get.back(result: index),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          SizedBox(
            height: 52,
            child: Center(
              child: QkdText(
                liveList[index].name ?? "",
                fontSize: 17,
                color: liveList[index].expertId == select?
                Colours.main:Colours.white
              )
            ),
          ),
          if(liveList[index].expertId != null)...[
            Container(width: 2),
            const GifWidget(
              width: 16,
              height: 16,
              asset: 'in_live_48.gif',
              duration: Duration(milliseconds: 500)
            )
          ]
        ],
      ),
    );
  }
}
